<template>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="名称" prop="name">
      <el-input v-model="ruleForm.name"></el-input>
    </el-form-item>
    <el-form-item label="描述" prop="nickName">
      <el-input v-model="ruleForm.desoptions" type="textarea" :rows="2"></el-input>
    </el-form-item>
    <el-form-item label="启用" prop="sex">
      <el-switch
        v-model="ruleForm.status"
        active-color="#13ce66"
        inactive-color="#ff4949"
        active-value="1"
        inactive-value="2">
      </el-switch>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm">保存</el-button>
      <el-button @click="$router.back()">取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>

export default {
  name: 'userEdit',
  components: {
  },
  data(){
    return {
      ruleForm:{
        name:'',
        desoptions:'',
        status:'1',
        _id:''
      },
      rules:{
        name:[
          { required: true, message: '请输入群组名称', trigger: 'blur' }
        ]
      }
    }
  },
  methods:{
    submitForm(){
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.$http({
            url:'/v1/group',
            method:!this.ruleForm._id ? 'POST' : 'PUT',
            data:this.ruleForm
          }).then(res => {
            if(!res.errorMsg){
              this.$message({
                message: !this.ruleForm._id ? '添加群组成功' : '修改群组信息成功',
                type: 'success'
              });
              this.$router.back()
            }
          })
        } else {
          return false;
        }
      })
    },
    getDetail(_id){
      this.$http({
        url:'/v1/groupInfo',
        params:{
          _id
        }
      }).then(res => {
        if(!res.errorMsg) {
          this.ruleForm = res
        }
      })
    }
  },
  created(){
    let _id = this.$route.query._id
    if(_id) this.getDetail(_id)
  },
  mounted(){
  }
}
</script>

<style scoped>

</style>
